package cmd

import (
	"context"
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/net/ghttp"
	"github.com/gogf/gf/v2/os/gcmd"
	"zuhao-seucre/internal/controller/auth"
	"zuhao-seucre/internal/controller/common"
	"zuhao-seucre/internal/controller/db"
	"zuhao-seucre/internal/controller/machines"
	"zuhao-seucre/internal/controller/mongos"
	"zuhao-seucre/internal/controller/msgs"
	"zuhao-seucre/internal/controller/redis"
	"zuhao-seucre/internal/controller/system"
	"zuhao-seucre/internal/controller/tag"
	"zuhao-seucre/internal/service"
)

var (
	Main = gcmd.Command{
		Name:  "main",
		Usage: "main",
		Brief: "start http server",
		Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
			s := g.Server()
			s.Group("/api", func(group *ghttp.RouterGroup) {
				group.Middleware(service.Middleware().ZuHaoCORS)
				group.Middleware(service.Middleware().ZuHaoCtx)
				group.Middleware(service.Middleware().ZuHaoAuthToken)
				group.Middleware(service.Middleware().ZuHaoResponse)
				group.Bind(
					auth.NewV1(),
					system.NewV1(),
					common.NewV1(),
					tag.NewV1(),
					redis.NewV1(),
					mongos.NewV1(),
					db.NewV1(),
					machines.NewV1(),
					msgs.NewV1(),
				)
			})
			s.Run()
			return nil
		},
	}
)
